home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-02-05 | 72.5 KB | 2,536 lines | [TEXT/MPS ] |
- // Copyright © 1991 Apple Computer, Inc. All rights reserved.
-
- #ifndef __UTARO__
- #include "UTaro.h"
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __PPCTOOLBOX__
- #include <PPCToolbox.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- extern TTaroApplication * gTaroApplication;
- Boolean gColorAvailable;
-
- const short kWindRsrcID = 1000;
- const short kBlackCursor = 1000;
- const short kWhiteCursor = 1001;
- const short kNotAvailable = 1002;
- const short kBlackCTable = 1000;
- const short kWhiteCTable = 1001;
- const short kEmptyCTable = 1002;
- const short kGameOverDraw = 2000;
- const short kFilename = 2001;
-
- const short kSubstitutionKey = 2002;
-
- const OSType kPreference = 'Pref';
-
- const ResType kLocalResource = rAliasType;
- const ResType kRemoteResource = 'REMT';
-
- const CommandNumber cNewPreference = cNewServer + 1;
- const CommandNumber cOpenPreference = cOpen + 1;
-
- const CommandNumber cAddRemote = 1000;
- const CommandNumber cRemoveRemote = 1001;
- const CommandNumber cAddLocal = 1002;
- const CommandNumber cRemoveLocal = 1003;
-
- const CommandNumber cSound = 2000;
-
- // ============================== AppleEvent Handler=================================
- pascal OSErr ReceiveApplicationDied(AppleEvent & theAppleEvent, AppleEvent & /*reply*/,
- long /*handlerRefcon*/)
- {
- DescType typeCode;
- Size actualSize;
- long Error;
- ProcessSerialNumber thePSN;
-
- FailOSErr(AEGetParamPtr(theAppleEvent, keyErrorNumber, typeLongInteger,
- typeCode, (Ptr)&Error, sizeof(Error), actualSize));
- FailOSErr(AEGetParamPtr(theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber,
- typeCode, (Ptr)&thePSN, sizeof(thePSN), actualSize));
- gTaroApplication->ReturnPreference()->ProcessDied((OSErr)Error, thePSN);
-
- return noErr;
- }
-
- // ------------------------------------------------------------------------
- pascal OSErr ReceiveReply(AppleEvent & theAppleEvent, AppleEvent & /*reply*/,
- long /*handlerRefcon*/)
- {
- DescType typeCode;
- Size actualSize;
- unsigned long aTargetTransactionID;
- AEDesc objSpec;
-
- TAppleEvent * aMessage = new TAppleEvent;
- aMessage->InitializeFromMessage(theAppleEvent, TRUE);
- TClientAEPlayer * MyClientAEPlayer = (TClientAEPlayer *)aMessage->GetTransactionID();
- if(IsObject(MyClientAEPlayer))
- if(IsMemberClassID(MyClientAEPlayer, GetClassIDFromName("TClientAEPlayer")))
- {
- long returnID = aMessage->GetReturnID();
- switch(returnID)
- {
- case kNewElementReturnID:
- aMessage->ReadParameter(keyDirectObject, typeObjectSpecifier, objSpec);
- MyClientAEPlayer->SetTargetTableSpecifier(objSpec);
- break;
- case kBeginTransactionReturnID:
- aMessage->ReadParameterPtr(keyAETheTransID, typeLongInteger, typeCode, (Ptr)&aTargetTransactionID, sizeof(aTargetTransactionID), actualSize);
- MyClientAEPlayer->TargetReply(aTargetTransactionID);
- break;
- default:
- break;
- }
- }
-
- return noErr;
- }
-
- // ------------------------------------------------------------------------
- pascal Boolean TaroApplicationFilter(LocationNameRec * /*theLocationNameRec*/, PortInfoRec * thePortInfoRec)
- {
- Str255 AppName;
- const short kApplicationNameID = 255;
- long offset, length;
- Handle itlHandle;
-
- for(short index = 1; ;index++)
- {
- GetIndString(AppName, kApplicationNameID, index);
- if(*AppName == 0)
- return FALSE;
- IUGetItlTable(iuSystemScript, iuWordSelectTable, itlHandle, offset, length);
- if(!IUEqualPString((char *)AppName, (char *)thePortInfoRec->name.name, itlHandle))
- return TRUE;
- }
- }
-
- OSErr TaroPPCBrowser(LocationNameRec & theLocationNameRec, PortInfoRec & thePortInfoRec)
- {
- Str255 prompt, applListLabel;
- Boolean defaultSpecified;
- Str32 theLocNBPType = "";
- const short kPPCBrowserPrompt = 2005;
- const short kPrompt = 1;
- const short kLabel = 2;
-
- GetIndString(prompt, kPPCBrowserPrompt, kPrompt);
- GetIndString(applListLabel, kPPCBrowserPrompt, kLabel);
- defaultSpecified = false;
-
- return PPCBrowser((char *)prompt, (char *)applListLabel, defaultSpecified, theLocationNameRec,
- thePortInfoRec, TaroApplicationFilter, theLocNBPType);
- }
-
- // ============================== TTaroApplication =================================
- #pragma segment AInit
- pascal void TTaroApplication::ITaroApplication(void)
- {
- inherited::ITaroApplication();
-
- gColorAvailable = FALSE;
-
- fClientHCellSize = 3;
- fClientVCellSize = 3;
- fClientBlackPlayer = 1;
- fClientWhitePlayer = 1;
-
- FailNILResource((Handle)(fGameDrawMessage = GetString(kGameOverDraw)));
-
- FailNILResource(fBlackCursor = (Handle)GetCursor(kBlackCursor));
- FailNILResource(fWhiteCursor = (Handle)GetCursor(kWhiteCursor));
- FailNILResource(fNotAvailableCursor = (Handle)GetCursor(kNotAvailable));
-
- FailNILResource(fDiveSound = (Handle)GetResource('snd ', kDive));
- FailNILResource(fBangSound = (Handle)GetResource('snd ', kBang));
- FailNILResource(fPshooSound = (Handle)GetResource('snd ', kPshoo));
- FailNILResource(fWarnSound = (Handle)GetResource('snd ', kWarn));
- fSoundEnable = TRUE;
-
- fBlackDrawingEnvironment = new TColorDrawingEnvironment;
- fBlackDrawingEnvironment->IColorDrawingEnvironment(kBlackCTable);
- fWhiteDrawingEnvironment = new TColorDrawingEnvironment;
- fWhiteDrawingEnvironment->IColorDrawingEnvironment(kWhiteCTable);
- fEmptyDrawingEnvironment = new TColorDrawingEnvironment;
- fEmptyDrawingEnvironment->IColorDrawingEnvironment(kEmptyCTable);
-
- fTaroEraser = new TTaroEraser;
- fTaroEraser->IEraseAdorner();
-
- if (gDeadStripSuppression) {
- TTaroWindow *aTaroWindow = new TTaroWindow;
- TTaroGridView *aTaroView = new TTaroGridView;
- TAboutGridView *anAboutGridView = new TAboutGridView;
- TInfoView *anInfoView = new TInfoView;
- TShadowView *aPlayerView = new TShadowView;
- TNumberStringView *aNumberText = new TNumberStringView;
- TStringView *aStringView = new TStringView;
- TStaticText *aStaticText = new TStaticText;
- TTaroStaticText *aTaroStaticText = new TTaroStaticText;
- TPopup *aPopup = new TPopup;
- TPlayerPopup *aPlayerPopup = new TPlayerPopup;
- TTargetListView *aPlayerListView = new TTargetListView;
- }
-
- FailOSErr(AEInstallEventHandler(kCoreEventClass, kAEApplicationDied,
- (EventHandlerProcPtr)ReceiveApplicationDied, 0, FALSE));
-
- FailOSErr(AEInstallEventHandler(kCoreEventClass, kAEAnswer,
- (EventHandlerProcPtr)ReceiveReply, 0, FALSE));
-
- FailOSErr(AESetInteractionAllowed(kAEInteractWithAll));
-
- TPreferenceFile * aFile = new TPreferenceFile;
- aFile->IPreferenceFile();
-
- HParamBlockRec pb;
-
- if(aFile->GetFileInfo(pb) == fnfErr)
- {
- OpenNew(cNewPreference);
- aFile->Free();
- }
- else
- OpenOld(cOpenPreference, aFile);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal TColorDrawingEnvironment * TTaroApplication::GetDrawingEnvironment(CellState aColor)
- {
- switch(aColor)
- {
- case kBlack:
- return fBlackDrawingEnvironment;
- case kWhite:
- return fWhiteDrawingEnvironment;
- default:
- return fEmptyDrawingEnvironment;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal Boolean TTaroApplication::NewDocumentDialog(char & aHSize, char & aVSize,
- char & aBlackPlayer, char & aWhitePlayer, Str255 aClientName)
- {
- const short kModalID = 1001;
- const IDType kDialogView = 'DLVW';
- const IDType kDialogWindow = 'WIND';
- const IDType kBlackPopup = 'BLCK';
- const IDType kWhitePopup = 'WHIT';
- const IDType kHSizePopup = 'HSIZ';
- const IDType kVSizePopup = 'VSIZ';
- const IDType kNewGame = 'GAME';
- const IDType kCancel = 'CNCL';
-
- char theHSize, theVSize, theBlackPlayer, theWhitePlayer;
-
- TWindow * aWindow = gViewServer->NewTemplateWindow(kModalID, NULL);
- TPopup * aHSizePopup = (TPopup *)aWindow->FindSubView(kHSizePopup);
- aHSizePopup->SetCurrentItem((short)aHSize, FALSE);
- TPopup * aVSizePopup = (TPopup *)aWindow->FindSubView(kVSizePopup);
- aVSizePopup->SetCurrentItem((short)aVSize, FALSE);
- TPlayerPopup * aBlackPopup = (TPlayerPopup *)aWindow->FindSubView(kBlackPopup);
- TPlayerPopup * aWhitePopup = (TPlayerPopup *)aWindow->FindSubView(kWhitePopup);
-
- if((aBlackPlayer == kServerAEPlayer) || (aWhitePlayer == kServerAEPlayer))
- {
- aHSizePopup->ViewEnable(FALSE, FALSE);
- aVSizePopup->ViewEnable(FALSE, FALSE);
- }
- if(aBlackPlayer == kServerAEPlayer)
- aBlackPopup->SetClientName(aClientName);
- else
- aBlackPopup->SetCurrentItem((short)aBlackPlayer, FALSE);
-
- if(aWhitePlayer == kServerAEPlayer)
- aWhitePopup->SetClientName(aClientName);
- else
- aWhitePopup->SetCurrentItem((short)aWhitePlayer, FALSE);
-
- IDType Dismisser = aWindow->PoseModally();
- theHSize = (char)aHSizePopup->GetCurrentItem();
- theVSize = (char)aVSizePopup->GetCurrentItem();
- theBlackPlayer = (char)aBlackPopup->GetCurrentItem();
- theWhitePlayer = (char)aWhitePopup->GetCurrentItem();
- aWindow->Close();
- if(Dismisser == kNewGame)
- {
- aHSize = theHSize;
- aVSize = theVSize;
- aBlackPlayer = theBlackPlayer;
- aWhitePlayer = theWhitePlayer;
- return TRUE;
- }
- else
- return FALSE;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal CommandNumber TTaroApplication::KindOfDocument(CommandNumber itsCommandNumber, TFile* aFile)
- {
- CommandNumber aCommandNumber = itsCommandNumber;
-
- switch(itsCommandNumber)
- {
- case cFinderOpen:
- case cOpen:
- if(IsObject(aFile))
- {
- OSType aFileType;
-
- FailOSErr(aFile->GetFileType(aFileType));
- if(aFileType == kPreference)
- aCommandNumber = cOpenPreference;
- }
- break;
- case cNewPreference:
- case cOpenPreference:
- aCommandNumber = cOpenPreference;
- break;
- case cFinderNew:
- aCommandNumber = cNewClient;
- break;
- default:
- break;
- }
- return aCommandNumber;
- }
-
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal TFile* TTaroApplication::DoMakeFile(CommandNumber itsCommandNumber)
- {
- if(itsCommandNumber == cNewPreference)
- {
- TPreferenceFile * aFile = new TPreferenceFile;
- aFile->IPreferenceFile();
- return aFile;
- }
- else
- return inherited::DoMakeFile(itsCommandNumber);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal TDocument *TTaroApplication::DoMakeDocument(CommandNumber itsCommandNumber, TFile* itsFile)
- {
- char aHCellSize, aVCellSize, aColor;
- Str255 aName;
- TDocument * newDocument = NULL;
- TAppleEventPlayer * aServerPlayer = NULL;
- VOLATILE(newDocument);
- FailInfo fi;
-
- switch(itsCommandNumber)
- {
- case cNewClient:
- case cFinderNew:
- newDocument = new TVisibleDocument;
-
- if (fi.Try())
- {
- ((TVisibleDocument *)newDocument)->IVisibleDocument(TranslateCellSize(fClientHCellSize), TranslateCellSize(fClientVCellSize),
- fClientBlackPlayer, fClientWhitePlayer);
- fi.Success();
- }
- else
- {
- FreeIfObject(newDocument);
- fi.ReSignal();
- }
- break;
- case cNewServer:
- newDocument = new TServerDocument;
- if (fi.Try())
- {
- (gTaroApplication->GetNewElementCommand())->GetServerParameter(aHCellSize, aVCellSize, aColor, aServerPlayer);
- ((TServerDocument *)newDocument)->IServerDocument(TranslateCellSize(aHCellSize), TranslateCellSize(aVCellSize),
- fServerPlayer, (CellState)aColor, aServerPlayer);
- fi.Success();
- }
- else
- {
- newDocument->Free();
- fi.ReSignal();
- }
- break;
- case cNewPreference:
- case cOpenPreference:
- newDocument = new TPreferenceDocument;
- if (fi.Try())
- {
- ((TPreferenceDocument *)newDocument)->IPreferenceDocument(itsFile);
- fPreferenceDocument = (TPreferenceDocument *)newDocument;
- fi.Success();
- }
- else
- {
- newDocument->Free();
- fi.ReSignal();
- }
- }
- return newDocument;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TTaroApplication::OpenNew(CommandNumber itsCommandNumber)
- {
- char aHCellSize, aVCellSize, aBlackPlayer, aWhitePlayer;
- TAppleEventPlayer * aServerPlayer;
- Str255 aName;
-
- switch(itsCommandNumber)
- {
- case cNewClient:
- aHCellSize = fClientHCellSize;
- aVCellSize = fClientVCellSize;
- aBlackPlayer = fClientBlackPlayer;
- aWhitePlayer = fClientWhitePlayer;
- if(NewDocumentDialog(aHCellSize, aVCellSize, aBlackPlayer, aWhitePlayer, NULL))
- {
- fClientHCellSize = aHCellSize;
- fClientVCellSize = aVCellSize;
- fClientBlackPlayer = aBlackPlayer;
- fClientWhitePlayer = aWhitePlayer;
- inherited::OpenNew(itsCommandNumber);
- }
- break;
- case cNewServer:
- char aServerColor;
-
- GetNewElementCommand()->GetServerParameter(aHCellSize, aVCellSize, aServerColor, aServerPlayer);
- if(aServerColor == kBlack)
- {
- aBlackPlayer = kMousePlayer;
- aWhitePlayer = kServerAEPlayer;
- }
- else
- {
- aBlackPlayer = kServerAEPlayer;
- aWhitePlayer = kMousePlayer;
- }
- // FailOSErr(AEInteractWithUser(kAEDefaultTimeout, NULL, NULL));
- aServerPlayer->GetName(aName);
- TSoundCommand * aSoundCommand = new TSoundCommand;
- aSoundCommand->ISoundCommand(kDive);
- PostCommand(aSoundCommand);
- if(NewDocumentDialog(aHCellSize, aVCellSize, aBlackPlayer, aWhitePlayer, aName))
- {
- fServerPlayer = (aServerColor == kBlack ? aBlackPlayer : aWhitePlayer);
- inherited::OpenNew(itsCommandNumber);
- }
- break;
- default:
- inherited::OpenNew(itsCommandNumber);
- break;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AInit
- pascal void TTaroApplication::GetFileTypeList(CommandNumber itsCommandNumber, TypeListHandle& typeList)
- {
- inherited::GetFileTypeList(itsCommandNumber, typeList);
- switch(itsCommandNumber)
- {
- case cFinderOpen:
- case cOpen:
- if(IsHandle((Handle)typeList))
- {
- SetHandleSize((Handle)typeList, GetHandleSize((Handle)typeList) + 4);
- (*typeList)[1] = kPreference;
- }
- else
- {
- typeList = (TypeListHandle)NewHandle(4);
- FailNIL(typeList);
- (*typeList)[0] = kPreference;
- }
- break;
- case cOpenPreference:
- if(!IsHandle((Handle)typeList))
- {
- typeList = (TypeListHandle)NewHandle(4);
- FailNIL(typeList);
- }
- (*typeList)[0] = kPreference;
- break;
- default:
- break;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal Handle TTaroApplication::GetColorCursor(short aCursor)
- {
- switch(aCursor)
- {
- case kBlackCursor:
- return fBlackCursor;
- case kWhiteCursor:
- return fWhiteCursor;
- case kNotAvailable:
- return fNotAvailableCursor;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TTaroApplication::PutColorCursor(short aCursor, Handle theCursor)
- {
- switch(aCursor)
- {
- case kBlackCursor:
- fBlackCursor = theCursor;
- break;
- case kWhiteCursor:
- fWhiteCursor = theCursor;
- break;
- case kNotAvailable:
- fNotAvailableCursor = theCursor;
- break;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TTaroApplication::SetColorCursor(short aCursor)
- {
- SetCursor(**((CursHandle)GetColorCursor(aCursor)));
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal StringHandle TTaroApplication::ReturnGameDrawMessage(void)
- {
- return fGameDrawMessage;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal short TTaroApplication::GetDepth(void)
- {
- return 1;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal TTaroEraser * TTaroApplication::GetTaroEraser(void)
- {
- return fTaroEraser;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal TPreferenceDocument * TTaroApplication::ReturnPreference(void)
- {
- return fPreferenceDocument;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TTaroApplication::DoAboutBox(void)
- {
- Handle aFlySound = NULL;
- Boolean soundFlag = FALSE;
- TWindow * aWindow = gViewServer->NewTemplateWindow(1006, NULL);
- if(fSoundEnable)
- {
- aFlySound = GetResource('snd ', kFly);
- if((ResError() == noErr) && IsHandle(aFlySound))
- {
- soundFlag = TRUE;
- SndPlay(NULL, aFlySound, FALSE);
- }
- }
- aWindow->PoseModally();
- aWindow->Close();
- if(soundFlag)
- ReleaseResource(aFlySound);
- }
-
- // ------------------------------------------------------------------------
- void DrawFrame(const Rect & aRect, TColorDrawingEnvironment * aDrawingEnvironment)
- {
- aDrawingEnvironment->SetupAdornerColor(kTopLeftLine);
- MoveTo(aRect.left, aRect.bottom - 2);
- LineTo(aRect.left, aRect.top);
- LineTo(aRect.right - 2, aRect.top);
-
- aDrawingEnvironment->SetupAdornerColor(kBottomRightLine);
- MoveTo(aRect.right - 1, aRect.top + 1);
- LineTo(aRect.right - 1, aRect.bottom - 1);
- LineTo(aRect.left + 1, aRect.bottom - 1);
-
- aDrawingEnvironment->Setup();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroApplication::DrawCell(TView * aView, Rect & aQDRect)
- {
- TColorDrawingEnvironment * aDrawingEnvironment = (TColorDrawingEnvironment *)aView->GetDrawingEnvironment();
- aDrawingEnvironment->Setup();
- EraseRect(aQDRect);
-
- DrawFrame(aQDRect, aDrawingEnvironment);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TTaroApplication::DoMenuCommand(CommandNumber aCommandNumber)
- {
- switch(aCommandNumber)
- {
- case cAddRemote:
- fPreferenceDocument->AddRemoteTarget();
- break;
- case cRemoveRemote:
- fPreferenceDocument->PlayerRemoveDialog(kRemoteAEPlayer);
- break;
- case cAddLocal:
- fPreferenceDocument->AddLocalTarget();
- break;
- case cRemoveLocal:
- fPreferenceDocument->PlayerRemoveDialog(kLocalAEPlayer);
- break;
- case cSound:
- ToggleSoundMenu();
- break;
- default:
- inherited::DoMenuCommand(aCommandNumber);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TTaroApplication::DoSetupMenus(void)
- {
- const short kSoundMenuString = 2006;
- const short mSoundMenu = 4;
-
- Enable(cAddRemote, TRUE);
- if(fPreferenceDocument->GetRemoteTargetListSize() != 0)
- Enable(cRemoveRemote, TRUE);
- Enable(cAddLocal, TRUE);
- if(fPreferenceDocument->GetLocalTargetListSize() != 0)
- Enable(cRemoveLocal, TRUE);
- Enable(cSound, TRUE);
- inherited::DoSetupMenus();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TTaroApplication::ToggleSoundMenu(void)
- {
- const short kSoundMenuString = 2006;
- const short mSoundMenu = 4;
- Str255 aMenuString;
- short Item;
-
- if(fSoundEnable)
- {
- fSoundEnable = FALSE;
- Item = 2;
- }
- else
- {
- fSoundEnable = TRUE;
- Item = 1;
- }
- MenuHandle soundMenu = MAGetMenu(mSoundMenu);
- GetIndString(aMenuString, kSoundMenuString, Item);
- SetItem(soundMenu, 1, aMenuString);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal TAppleEventPlayer * TTaroApplication::CreateServerPlayer(void)
- {
- return new TServerAEPlayer;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TTaroApplication::PlaySound(SoundEffect aSound)
- {
- if(fSoundEnable)
- {
- Handle aSoundHandle = NULL;
- switch(aSound)
- {
- case kDive:
- aSoundHandle = fDiveSound;
- break;
- case kBang:
- aSoundHandle = fBangSound;
- break;
- case kPshoo:
- aSoundHandle = fPshooSound;
- break;
- case kWarn:
- aSoundHandle = fWarnSound;
- break;
- default:
- break;
- }
- if(IsHandle(aSoundHandle))
- FailOSErr(SndPlay(NULL, aSoundHandle, FALSE));
- }
- }
-
- // ============================== TTargetListView =================================
- #pragma segment AOpen
- pascal void TTargetListView::SetUp(TList * aTargetList)
- {
- fTargetList = aTargetList;
- DelRowFirst(1);
- InsItemLast((short)fTargetList->GetSize());
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TTargetListView::GetItemText(short anItem, Str255 & aString)
- {
- ((TClientTarget *)fTargetList->At(anItem))->GetName(aString);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TTargetListView::SelectItem(short anItem, Boolean extendedSelection, Boolean highlight, Boolean select)
- {
- Boolean RemoveButton;
-
- if(!select)
- RemoveButton = FALSE;
- else
- RemoveButton = (((TClientTarget *)fTargetList->At(anItem))->GetUserCount() == 0);
- (gTaroApplication->ReturnPreference())->SetButtonState(RemoveButton);
- inherited::SelectItem(anItem, extendedSelection, highlight, select);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TTargetListView::DeleteSelectedTarget(void)
- {
- short anItem = FirstSelectedItem();
- if(anItem != 0)
- {
- TClientTarget * SelectedTarget = (TClientTarget *)fTargetList->At(anItem);
- fTargetList->AtDelete(anItem);
- SelectedTarget->Remove();
- SelectedTarget->Free();
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TTargetListView::SelectFirstItem(void)
- {
- if((fNumOfRows != 0) && (FirstSelectedItem() == 0))
- SelectItem(1, FALSE, TRUE, TRUE);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal TClientTarget * TTargetListView::GetSelectedTarget(void)
- {
- short anItem = FirstSelectedItem();
- if(anItem != 0)
- return (TClientTarget *)fTargetList->At(anItem);
- else
- return NULL;
- }
-
-
- // ============================== TColorApplication =================================
- #pragma segment AInit
- pascal void TColorApplication::ITaroApplication(void)
- {
- Handle theCursor;
-
- inherited::ITaroApplication();
-
- fOldDepth = 1;
-
- FailNILResource(theCursor = (Handle)GetCCursor(kBlackCursor));
- PutColorCursor(kBlackCursor, theCursor);
- FailNILResource(theCursor = (Handle)GetCCursor(kWhiteCursor));
- PutColorCursor(kWhiteCursor, theCursor);
- FailNILResource(theCursor = (Handle)GetCCursor(kNotAvailable));
- PutColorCursor(kNotAvailable, theCursor);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TColorApplication::ChangePixelDepth(short depth)
- {
- if(fOldDepth != depth)
- {
- if(depth != 1)
- {
- GetDrawingEnvironment(kBlack)->MakePixPatTable();
- GetDrawingEnvironment(kWhite)->MakePixPatTable();
- GetDrawingEnvironment(kEmpty)->MakePixPatTable();
- }
- fOldDepth = depth;
- if(gConfiguration.hasColorQD && (fOldDepth != 1))
- gColorAvailable = TRUE;
- else
- gColorAvailable = FALSE;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal short TColorApplication::GetDepth(void)
- {
- return fOldDepth;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TColorApplication::SetColorCursor(short aCursor)
- {
- SetCCursor((CCrsrHandle)GetColorCursor(aCursor));
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TColorApplication::DrawCell(TView * aView, Rect & aQDRect)
- {
- if(gColorAvailable)
- {
- TColorDrawingEnvironment * aDrawingEnvironment = (TColorDrawingEnvironment *)aView->GetDrawingEnvironment();
- aDrawingEnvironment->Setup();
- EraseRect(aQDRect);
-
- DrawFrame(aQDRect, aDrawingEnvironment);
- aQDRect.top++;
- aQDRect.left++;
- aQDRect.bottom--;
- aQDRect.right--;
- DrawFrame(aQDRect, aDrawingEnvironment);
- }
- else
- inherited::DrawCell(aView, aQDRect);
- }
-
- // ============================== TPreferenceDocument =================================
- #pragma segment AOpen
- pascal void TPreferenceDocument::IPreferenceDocument(TFile * itsFile)
- {
- TList * aList;
-
- IFileBasedDocument(itsFile, kPreference);
- fSavePrintInfo = false;
-
- FailNIL(aList = NewList());
- fRemoteTargetList = aList;
- fRemoteTargetList->SetEltType("TPPCTarget");
-
- FailNIL(aList = NewList());
- fLocalTargetList = aList;
- fLocalTargetList->SetEltType("TPSNTarget");
-
- fIdleFreq =2;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPreferenceDocument::PlayerRemoveDialog(Player ID)
- {
- const short kListDialogID = 1005;
- const IDType kDialogView = 'LSDL';
- const IDType kDialogWindow = 'LSTW';
- const IDType kPrompt = 'MSSG';
- const IDType kRemoveTarget = 'RMVE';
- const IDType kCancel = 'CNCL';
- const IDType kPlayerList = 'LSVW';
- const short kPromptString = 2003;
-
- Str255 Prompt;
- IDType Dismisser;
-
- TWindow * aWindow = gViewServer->NewTemplateWindow(kListDialogID, NULL);
- TTargetListView * aPlayerListView = (TTargetListView *)aWindow->FindSubView(kPlayerList);
- TStaticText * aStaticText = (TStaticText *)aWindow->FindSubView(kPrompt);
- fRemoveButton = (TButton *)aWindow->FindSubView(kRemoveTarget);
- GetIndString(Prompt, kPromptString, ID);
- aStaticText->SetText(Prompt, FALSE);
-
- if(ID == kRemoteAEPlayer)
- aPlayerListView->SetUp(fRemoteTargetList);
- else if(ID == kLocalAEPlayer)
- aPlayerListView->SetUp(fLocalTargetList);
-
- aPlayerListView->SelectFirstItem();
- Dismisser = aWindow->PoseModally();
- if(Dismisser == kRemoveTarget)
- {
- short currentRes = (GetFileHandler()->GetFile())->UseResource();
- aPlayerListView->DeleteSelectedTarget();
- UseResFile(currentRes);
- }
- aWindow->Close();
- }
-
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPreferenceDocument::SetButtonState(Boolean RemoveButton)
- {
- const short kRemoveString = 2004;
- const short kRemove = 1;
- const short kInUse = 2;
- Str255 aString;
-
- if(!RemoveButton)
- GetIndString(aString, kRemoveString, kInUse);
- else
- GetIndString(aString, kRemoveString, kRemove);
- fRemoveButton->SetText(aString, FALSE);
- fRemoveButton->DimState(!RemoveButton, FALSE);
- fRemoveButton->ViewEnable(RemoveButton, TRUE);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPreferenceDocument::AddRemoteTarget(void)
- {
- TargetIDHdl toTargetID = (TargetIDHdl)NewHandle(sizeof(TargetID));
- PortInfoRec thePortInfoRec;
-
- LockHandleHigh((Handle)toTargetID);
- if(TaroPPCBrowser((*toTargetID)->location, thePortInfoRec) == noErr)
- {
- Str255 Name;
-
- (*toTargetID)->name = thePortInfoRec.name;
- HUnlock((Handle)toTargetID);
-
- TPPCTarget * aRemoteTarget = new TPPCTarget;
- FailNIL(aRemoteTarget);
- aRemoteTarget->IPPCTarget(toTargetID);
- aRemoteTarget->GetName(Name);
- fRemoteTargetList->InsertFirst(aRemoteTarget);
-
- short currentRes = (GetFileHandler()->GetFile())->UseResource();
- AddResource((Handle)toTargetID, kRemoteResource, Unique1ID(kRemoteResource), Name);
- FailResError();
- UseResFile(currentRes);
- }
- else
- {
- HUnlock((Handle)toTargetID);
- DisposHandle((Handle)toTargetID);
- }
- }
-
- // ------------------------------------------------------------------------
- pascal Boolean LocalTaroFilter(CInfoPBPtr pb)
- {
- if((pb->hFileInfo.ioFlFndrInfo.fdCreator == kServerSignature)
- && (pb->hFileInfo.ioFlFndrInfo.fdType == kApplicationFType))
- return FALSE;
- else
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPreferenceDocument::AddLocalTarget(void)
- {
- StandardFileReply MyReply;
- SFTypeList aTypeList;
-
- aTypeList[0] = 'APPL';
-
- StandardGetFile((FileFilterProcPtr)LocalTaroFilter, 1, aTypeList, MyReply);
-
- if(MyReply.sfGood)
- {
- AliasHandle anAliasHandle;
- Str255 Name;
-
- FailOSErr(NewAlias(NULL, MyReply.sfFile, anAliasHandle));
-
- TPSNTarget * aLocalTarget = new TPSNTarget;
- FailNIL(aLocalTarget);
- aLocalTarget->IPSNTarget(anAliasHandle);
- aLocalTarget->GetName(Name);
- fLocalTargetList->InsertFirst(aLocalTarget);
-
- short currentRes = (GetFileHandler()->GetFile())->UseResource();
- AddResource((Handle)anAliasHandle, kLocalResource, Unique1ID(kLocalResource), Name);
- FailResError();
- UseResFile(currentRes);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TPreferenceDocument::Free(void)
- {
- (GetFileHandler()->GetFile())->UpdateResource();
- fRemoteTargetList->FreeList();
- fLocalTargetList->FreeList();
- inherited::Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TPreferenceDocument::ProcessDied(OSErr /*anError*/, ProcessSerialNumber & theProcess)
- {
- if(GetLocalTargetListSize() != 0)
- {
- CObjectIterator iter(fLocalTargetList);
-
- for (TPSNTarget * aTarget = (TPSNTarget *)iter.FirstObject(); iter.More(); aTarget = (TPSNTarget *)iter.NextObject())
- aTarget->CompareProcess(theProcess);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal short TPreferenceDocument::AppendPlayerMenu(MenuHandle theMenu)
- {
- short ItemNumber = 0;
- if(GetRemoteTargetListSize() != 0)
- {
- CObjectIterator iter(fRemoteTargetList);
- AppendMenu(theMenu, "-");
- ItemNumber++;
-
- for (TClientTarget * aTarget = (TClientTarget *)iter.FirstObject(); iter.More(); aTarget = (TClientTarget *)iter.NextObject())
- {
- Str255 Name;
-
- aTarget->GetName(Name);
- AppendMenu(theMenu, "Dummy");
- SetItem(theMenu, CountMItems(theMenu), Name);
- ItemNumber++;
- }
- }
- if(GetLocalTargetListSize() != 0)
- {
- CObjectIterator iter(fLocalTargetList);
-
- AppendMenu(theMenu, "-");
- ItemNumber++;
- for (TClientTarget * aTarget = (TClientTarget *)iter.FirstObject(); iter.More(); aTarget = (TClientTarget *)iter.NextObject())
- {
- Str255 Name;
-
- aTarget->GetName(Name);
- AppendMenu(theMenu, "Dummy");
- SetItem(theMenu, CountMItems(theMenu), Name);
- ItemNumber++;
- }
- }
- return ItemNumber;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal short TPreferenceDocument::GetRemoteTargetListSize(void)
- {
- return (short)fRemoteTargetList->GetSize();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal short TPreferenceDocument::GetLocalTargetListSize(void)
- {
- return (short)fLocalTargetList->GetSize();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal TClientTarget * TPreferenceDocument::ReturnIndexedTarget(short index) // base 1
- {
- short RemoteListSize = GetRemoteTargetListSize();
- if(RemoteListSize != 0)
- index--;
- if(index <= RemoteListSize)
- return (TClientTarget *)fRemoteTargetList->At(index);
- else
- {
- index -= RemoteListSize;
- short LocalListSize = GetLocalTargetListSize();
- if(LocalListSize != 0)
- index--;
- if(index <= LocalListSize)
- return (TClientTarget *)fLocalTargetList->At(index);
- else
- return NULL;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPreferenceDocument::DoRead(TFile* aFile, Boolean forPrinting)
- {
- short Count;
- short ResourceNumber;
-
- inherited::DoRead(aFile, forPrinting);
- short savedResFile = aFile->UseResource();
- if((ResourceNumber = Count1Resources(kLocalResource)) != 0)
- {
- for(Count = 1; Count <= ResourceNumber; Count ++)
- {
- AliasHandle aFile;
- FailNILResource((Handle)(aFile = (AliasHandle)Get1IndResource(kLocalResource, Count)));
- TPSNTarget * aLocalTarget = new TPSNTarget;
- FailNIL(aLocalTarget);
- aLocalTarget->IPSNTarget(aFile);
- fLocalTargetList->InsertLast(aLocalTarget);
- }
- }
- if((ResourceNumber = Count1Resources(kRemoteResource)) != 0)
- {
- for(Count = 1; Count <= ResourceNumber; Count ++)
- {
- TargetIDHdl aTargetID;
- FailNILResource((Handle)(aTargetID = (TargetIDHdl)Get1IndResource(kRemoteResource, Count)));
- TPPCTarget * aRemoteTarget = new TPPCTarget;
- FailNIL(aRemoteTarget);
- aRemoteTarget->IPPCTarget(aTargetID);
- fRemoteTargetList->InsertLast(aRemoteTarget);
- }
- }
- UseResFile(savedResFile);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPreferenceDocument::DoInitialState(void)
- {
- HParamBlockRec pb;
- OSErr anError;
- TPreferenceFile * aFile = (TPreferenceFile *)(GetFileHandler()->GetFile());
-
- if((anError = aFile->GetFileInfo(pb)) == fnfErr)
- aFile->CreateFile();
- else if(anError != noErr)
- FailOSErr(anError);
- FailOSErr(aFile->OpenFile());
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPreferenceDocument::DoMakeViews(Boolean /* forPrinting */)
- {
- }
-
-
- // ============================== TPlayerPopup =================================
- #pragma segment AOpen
- pascal void TPlayerPopup::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- SetMax((gTaroApplication->ReturnPreference())->AppendPlayerMenu(GetMenuHandle()) + GetMax(), FALSE);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPlayerPopup::SetClientName(Str255 aClientName)
- {
- MenuHandle aMenuHandle = GetMenuHandle();
- short MItems = CountMItems(aMenuHandle);
- while(MItems > 1)
- DelMenuItem(aMenuHandle, MItems--);
- // ViewEnable(FALSE, FALSE);
- SetItem(aMenuHandle, 1, aClientName);
- SetCurrentItem(1, FALSE);
- }
-
- // ============================== TPreferenceFile =================================
- #pragma segment AOpen
- pascal void TPreferenceFile::IPreferenceFile(void)
- {
- short foundVRefNum;
- long foundDirID;
- StringHandle Filename;
-
- IFile(kPreference, kSignature, FALSE, TRUE, FALSE, TRUE);
- FailNILResource((Handle)(Filename = GetString(kFilename)));
-
- FailOSErr(FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
- foundVRefNum, foundDirID));
- FailOSErr(SpecifyWithTrio(foundVRefNum, foundDirID, (Str63)(**Filename)));
- fRsrcPermission = fsRdWrPerm;
- }
-
-
- // ============================== TVisibleDocument =================================
- #pragma segment AOpen
- pascal void TVisibleDocument::IVisibleDocument(char aHCellSize, char aVCellSize,
- char aBlackPlayer, char aWhitePlayer)
- {
- TList * aList = NewList();
- FailNIL(aList);
- aList->SetEltType("TRecordCell");
- fMoveList = aList;
-
- fVisibleScene = NULL;
-
- ICoreDocument(aHCellSize, aVCellSize, aBlackPlayer, aWhitePlayer);
- fSavePrintInfo = true; // save print record
-
- fIdleFreq =2;
- }
-
- // ------------------------------------------------------------------------
- pascal TPlayer * TVisibleDocument::CreatePlayer(char PlayerType, CellState aColor)
- {
- TPlayer * NewPlayer = NULL;
- VOLATILE(NewPlayer);
- FailInfo fi;
-
- if(PlayerType == kMousePlayer)
- {
- NewPlayer = new TMousePlayer;
- if (fi.Try())
- {
- ((TMousePlayer *)NewPlayer)->IMousePlayer(this);
- fi.Success();
- }
- else
- {
- NewPlayer->GameOver(kClose);
- FreeIfObject(NewPlayer);
- fi.ReSignal();
- }
- }
- else
- {
- TClientTarget * aClientTarget = (gTaroApplication->ReturnPreference())->ReturnIndexedTarget(PlayerType-1);
- if(IsObject(aClientTarget))
- {
- NewPlayer = new TClientAEPlayer;
- if (fi.Try())
- {
- ((TClientAEPlayer *)NewPlayer)->IClientAEPlayer(this, aColor, aClientTarget);
- fi.Success();
- }
- else
- {
- NewPlayer->GameOver(kClose);
- FreeIfObject(NewPlayer);
- fi.ReSignal();
- }
- }
- }
- return NewPlayer;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TVisibleDocument::Free()
- {
- FreeIfObject(fVisibleScene);
- if(IsObject(fMoveList))
- fMoveList->FreeList();
- inherited::Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal TInfoView * TVisibleDocument::ReturnInfoView(void)
- {
- return fInfoView;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal TVisibleScene * TVisibleDocument::ReturnVisibleScene(void)
- {
- return fVisibleScene;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleDocument::ShowStatusMessage(Str255 & aMessage)
- {
- fInfoView->ShowStatusMessage(aMessage);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleDocument::DoMakeViews(Boolean forPrinting)
- {
- if(IsObject(GetPlayer(kBlackTurn)) && IsObject(GetPlayer(kWhiteTurn)))
- {
- Str255 aString;
-
- TTaroWindow * aWindow = (TTaroWindow *)gViewServer->NewTemplateWindow(kWindRsrcID, this);
-
- TView * aPrintView = aWindow->FindSubView('PRVW');
- fInfoView = (TInfoView *)aWindow->FindSubView('Info');
- fInfoView->SetColor(kEmpty);
- TNumberStringView * aBlackNumber = (TNumberStringView *)aWindow->FindSubView('Num1');
- aBlackNumber->SetColor(kBlack);
- TNumberStringView * aWhiteNumber = (TNumberStringView *)aWindow->FindSubView('Num2');
- aWhiteNumber->SetColor(kWhite);
- TShadowView * aBlackPlayer = (TShadowView *)aWindow->FindSubView('BLPV');
- aBlackPlayer->SetColor(kBlack);
- TShadowView * aWhitePlayer = (TShadowView *)aWindow->FindSubView('WHPV');
- aWhitePlayer->SetColor(kWhite);
- TTaroStaticText * aStaticText = (TTaroStaticText *)aWindow->FindSubView('TEXT');
- aStaticText->SetColor(kEmpty);
- TStringView * aBlackText = (TStringView *)aWindow->FindSubView('TXBL');
- TStringView * aWhiteText = (TStringView *)aWindow->FindSubView('TXWH');
- fInfoView->SetView(aBlackNumber, aWhiteNumber, aStaticText, aBlackText, aWhiteText);
- TShadowView * aBaseView = (TShadowView *)aWindow->FindSubView('Base');
- aBaseView->SetColor(kEmpty);
-
- GetPlayerName(kBlackTurn, aString);
- fInfoView->SetPlayer(kBlack, aString);
- GetPlayerName(kWhiteTurn, aString);
- fInfoView->SetPlayer(kWhite, aString);
-
- fTaroView = (TTaroGridView *)aWindow->FindSubView('Taro');
- fVisibleScene = new TVisibleScene;
- FailNIL(fVisibleScene);
-
- char hCellSize, vCellSize;
- GetCellSize(hCellSize, vCellSize);
- fTaroView->SetVisibleScene(fVisibleScene, (short)hCellSize, (short)vCellSize);
- fVisibleScene->IVisibleScene(fTaroView, this);
- fVisibleScene->SetInitialState();
-
- TStdPrintHandler *aStdHandler = new TStdPrintHandler;
- FailNIL(aStdHandler);
- aStdHandler->IStdPrintHandler( this, // document
- aPrintView, // view to be printed
- kSquareDots, // Tall Adjusted - true for bit maps
- kFixedSize, // width of each printed page fixed?
- kFixedSize); // height fixed ?
- }
- inherited::DoMakeViews(forPrinting);
- }
-
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleDocument::Save(CommandNumber /*itsCommandNumber*/, Boolean /*askForFileName*/,
- Boolean /*makingCopy*/)
- {
- NotYetImplemented((Str255)"");
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TVisibleDocument::GetPlayerName(GameState aColor, Str255 & aString)
- {
- GetPlayer(aColor)->GetName(aString);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TVisibleDocument::GameOver(void)
- {
- GameResult BlackResult, WhiteResult;
-
- inherited::GameOver();
- short BlackNumber = ReturnVisibleScene()->GetCount(kBlack);
- short WhiteNumber = ReturnVisibleScene()->GetCount(kWhite);
- if(BlackNumber > WhiteNumber)
- {
- BlackResult = kWin;
- WhiteResult = kLose;
- }
- else if(BlackNumber < WhiteNumber)
- {
- BlackResult = kLose;
- WhiteResult = kWin;
- }
- else
- {
- BlackResult = kDraw;
- WhiteResult = kDraw;
- Str255 aMessage((char *)(**(gTaroApplication->ReturnGameDrawMessage())));
- ShowStatusMessage(aMessage);
- }
- GetPlayer(kBlackTurn)->GameOver(BlackResult);
- GetPlayer(kWhiteTurn)->GameOver(WhiteResult);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TVisibleDocument::GameClose(void)
- {
- TPlayer * aPlayer;
-
- if(IsObject(aPlayer = GetPlayer(kBlackTurn)))
- aPlayer->GameOver(kClose);
- if(IsObject(aPlayer = GetPlayer(kWhiteTurn)))
- aPlayer->GameOver(kClose);
- inherited::GameOver();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleDocument::SendTurn(void)
- {
- if(GetTurn() != kGameOver)
- fVisibleScene->SetTurn(GetTurnCellState());
- inherited::SendTurn();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleDocument::MouseMove(TRecordCell * aMouseMove)
- {
- TPlayer * aPlayer;
-
- if(IsObject(aPlayer = GetTemporaryPlayer()))
- aPlayer->MouseMove(aMouseMove);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleDocument::PlayerMove(TRecordCell * aPlayerMove)
- {
- TCell * theCell;
-
- if(IsObject(aPlayerMove))
- {
- fMoveList->InsertLast(aPlayerMove);
- theCell = ReturnVisibleScene()->GetCell(aPlayerMove->GetColumn(), aPlayerMove->GetRow());
- theCell->PutPiece();
- TSoundCommand * aSoundCommand = new TSoundCommand;
- aSoundCommand->ISoundCommand(kBang);
- PostCommand(aSoundCommand);
- }
- inherited::PlayerMove(aPlayerMove);
- }
-
-
- // ============================== TServerDocument =================================
- #pragma segment AOpen
- pascal void TServerDocument::IServerDocument(char aHCellSize, char aVCellSize, char aPlayer,
- CellState aColor, TAppleEventPlayer * aServerPlayer)
- {
- char aBlackPlayer = (aColor == kBlack ? aPlayer : kServerAEPlayer);
- char aWhitePlayer = (aColor == kWhite ? aPlayer : kServerAEPlayer);
- fServerPlayer = aServerPlayer;
- IVisibleDocument(aHCellSize, aVCellSize, aBlackPlayer, aWhitePlayer);
- }
-
- // ------------------------------------------------------------------------
- pascal TPlayer * TServerDocument::CreatePlayer(char PlayerType, CellState aColor)
- {
- TPlayer * NewPlayer = NULL;
-
- if(PlayerType == kServerAEPlayer)
- {
- NewPlayer = fServerPlayer;
- ((TServerAEPlayer *)NewPlayer)->IServerAEPlayer(this, aColor);
- }
- else
- NewPlayer = inherited::CreatePlayer(PlayerType, aColor);
- return NewPlayer;
- }
-
-
- // ============================== TVisibleScene =================================
- #pragma segment AOpen
- pascal TCell * TVisibleScene::CreateCell(char aColumn, char aRow)
- {
- TVisibleCell * aVisibleCell = new TVisibleCell;
- FailNIL(aVisibleCell);
- AddCellLast(aVisibleCell);
- aVisibleCell->ICell(this, aColumn, aRow);
- return aVisibleCell;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleScene::IVisibleScene(TTaroGridView * aTaroView,
- TVisibleDocument * aCoreDocument)
- {
- fTaroView = aTaroView;
- IScene(aCoreDocument);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TVisibleScene::ChangeCount(CellState aColor, short aNumber)
- {
- inherited::ChangeCount(aColor, aNumber);
- if(aColor == kWhite)
- (((TVisibleDocument *)ReturnCoreDocument())->ReturnInfoView())->SetNumber(kWhite, GetCount(kWhite));
- else if(aColor == kBlack)
- (((TVisibleDocument *)ReturnCoreDocument())->ReturnInfoView())->SetNumber(kBlack, GetCount(kBlack));
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleScene::SetInitialState(void)
- {
- inherited::SetInitialState();
- SearchAvailableCell();
- }
-
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal TTaroGridView * TVisibleScene::ReturnTaroGridView(void)
- {
- return fTaroView;
- }
-
- // ============================== TVisibleGridView =================================
- #pragma segment AOpen
- pascal void TVisibleGridView::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- AddAdorner(gTaroApplication->GetTaroEraser(), kDrawView - 10, FALSE);
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(kEmpty);
- fIdleFreq = 2; // so DoSetCursor gets called often
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TVisibleGridView::Draw(const VRect& area)
- {
- Focus();
- if(gConfiguration.hasColorQD && (gTaroApplication->GetDepth() != 1))
- gColorAvailable = TRUE;
- else
- gColorAvailable = FALSE;
-
- inherited::Draw(area);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TVisibleGridView::DrawCell(GridCell aCell, const VRect& /* aRect */)
- {
- VRect cellRect;
- Rect qdRect;
-
- CellState aState = GetCellState(aCell);
- CellToVRect(aCell, cellRect);
- ViewToQDRect(cellRect, qdRect);
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(aState);
- gTaroApplication->DrawCell(this, qdRect);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal CellState TVisibleGridView::GetCellState(GridCell /*aCell*/)
- {
- SubClassResponsibility();
- return kEmpty;
- }
-
- // ============================== TTaroGridView =================================
- #pragma segment ARes
- pascal void TTaroGridView::ForceRedrawCell(TVisibleCell * aVisibleCell)
- {
- GridCell aCell((short)(aVisibleCell->GetColumn() + 1), (short)(aVisibleCell->GetRow() + 1));
- VRect cellRect;
-
- Focus();
- CellToVRect(aCell, cellRect);
- InvalidateVRect(cellRect);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroGridView::SetEraseColor(TVisibleCell * aVisibleCell)
- {
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(aVisibleCell->GetState());
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroGridView::SetVisibleScene(TVisibleScene * aVisibleScene, short hCellSize, short vCellSize)
- {
- VRect aFrame;
- VPoint size;
-
- fVisibleScene = aVisibleScene;
- GetFrame(aFrame);
- size = aFrame.Size();
- DelColFirst((short)fNumOfCols);
- InsColFirst(hCellSize, (short)(size.h / hCellSize));
- DelRowFirst((short)fNumOfRows);
- InsRowFirst(vCellSize, (short)(size.v / vCellSize));
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal CellState TTaroGridView::GetCellState(GridCell aCell)
- {
- return (fVisibleScene->GetCell(aCell.h - 1, aCell.v - 1))->GetState();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TTaroGridView::DoMouseCommand(VPoint& theMouse, TToolboxEvent* /*event*/, Point /*hysteresis*/)
- {
- GridCell aCell;
-
- if (IdentifyPoint(theMouse, aCell) == inCell)
- {
- TVisibleCell * aVisibleCell = (TVisibleCell *)(fVisibleScene->GetCell(aCell.h - 1, aCell.v - 1));
- if(aVisibleCell->IsAvailable())
- {
- TRecordCell * aMove = new TRecordCell;
- FailNIL(aMove);
- aMove->IRecordCell(aVisibleCell->GetColumn(), aVisibleCell->GetRow(), (aVisibleCell->GetScene())->GetTurn());
- ((TVisibleDocument *)fDocument)->MouseMove(aMove);
- }
- else
- gTaroApplication->PlaySound(kWarn);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroGridView::DoSetCursor(const VPoint& localPoint, RgnHandle cursorRegion)
- {
- VRect aCellRect;
- Rect QDRect;
- GridCell aCell;
-
- if (IdentifyPoint(localPoint, aCell) == inCell)
- {
- TVisibleCell * aVisibleCell = (TVisibleCell *)(fVisibleScene->GetCell(aCell.h - 1, aCell.v - 1));
- SetCursor(aVisibleCell);
- CellToVRect(aCell, aCellRect);
- ViewToQDRect(aCellRect, QDRect);
- RectRgn(cursorRegion, QDRect);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroGridView::SetCursor(TVisibleCell * aVisibleCell)
- {
- short aCursor;
-
- if(aVisibleCell->IsAvailable() == TRUE)
- {
- CellState aTurn = (aVisibleCell->GetScene())->GetTurn();
- if(aTurn == kBlack)
- aCursor = kBlackCursor;
- else if(aTurn == kWhite)
- aCursor = kWhiteCursor;
- }
- else
- aCursor = kNotAvailable;
- gTaroApplication->SetColorCursor(aCursor);
- }
-
- // ============================== TAboutGridView =================================
- #pragma segment AOpen
- pascal void TAboutGridView::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- for(short v = 0; v < kNumOfRow; v++)
- for(short h = 0; h < kNumOfColumn; h++)
- fAboutCell[h][v] = kEmpty;
- fTaroBitMapHandle = (TaroBitMapHandle)GetResource('HEXA', 128);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal CellState TAboutGridView::GetCellState(GridCell aCell)
- {
- return GetBitMapData(aCell) ? kBlack : kWhite;
- // return fAboutCell[aCell.h - 1][aCell.v - 1];
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TAboutGridView::SetCellState(GridCell aCell, CellState aState)
- {
- fAboutCell[aCell.h - 1][aCell.v - 1] = aState;
- VRect cellRect;
-
- Focus();
- CellToVRect(aCell, cellRect);
- InvalidateVRect(cellRect);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TAboutGridView::DoMouseCommand(VPoint& /*theMouse*/, TToolboxEvent* /*event*/, Point /*hysteresis*/)
- {
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal Boolean TAboutGridView::GetBitMapData(GridCell aCell)
- {
- return ((*fTaroBitMapHandle)->bitMapData[aCell.v - 1] >> (kNumOfColumn - aCell.h)) & 1;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TAboutGridView::Free(void)
- {
- ReleaseResource((Handle)fTaroBitMapHandle);
- inherited::Free();
- }
-
- // ============================== TTaroWindow =================================
- #pragma segment ARes
- pascal void TTaroWindow::Update(void)
- {
- if(gConfiguration.hasColorQD)
- ((TColorApplication *)gTaroApplication)->ChangePixelDepth((*((CGrafPtr)GetGrafPort())->portPixMap)->pixelSize);
- inherited::Update();
- }
-
- // ============================== TShadowView =================================
- #pragma segment AOpen
- pascal void TShadowView::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- AddAdorner(gTaroApplication->GetTaroEraser(), kDrawView - 10, FALSE);
- fIdleFreq = 0; // so DoSetCursor gets called often
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TShadowView::Draw(const VRect& /*area*/)
- {
- Rect aQDRect;
-
- GetQDExtent(aQDRect);
- gTaroApplication->DrawCell(this, aQDRect);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TShadowView::SetColor(CellState aColor)
- {
- fColor = aColor;
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(aColor);
- }
-
- // ============================== TTaroStaticText =================================
- #pragma segment AOpen
- pascal void TTaroStaticText::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- AddAdorner(gTaroApplication->GetTaroEraser(), kDrawView - 10, FALSE);
- fIdleFreq = 0; // so DoSetCursor gets called often
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroStaticText::Draw(const VRect& area)
- {
- if(fDrawingEnvironment)
- ((TColorDrawingEnvironment *)fDrawingEnvironment)->Setup();
- inherited::Draw(area);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroStaticText::SetColor(CellState aColor)
- {
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(aColor);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TTaroStaticText::SetText(const Str255 & aString, Boolean redraw)
- {
- if(fDrawingEnvironment && redraw)
- ((TColorDrawingEnvironment *)fDrawingEnvironment)->Setup();
- inherited::SetText(aString, redraw);
- }
-
- // ============================== TInfoView =================================
- #pragma segment AOpen
- pascal void TInfoView::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- fIdleFreq = 0; // so DoSetCursor gets called often
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TInfoView::SetView(TNumberStringView * aBlackNumber, TNumberStringView * aWhiteNumber,
- TTaroStaticText * aStaticText, TStringView * aBlackText, TStringView * aWhiteText)
- {
- fBlackNumber = aBlackNumber;
- fWhiteNumber = aWhiteNumber;
- fStaticText = aStaticText;
- fBlackText = aBlackText;
- fWhiteText = aWhiteText;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TInfoView::SetNumber(CellState aColor, short aNumber)
- {
- if(aColor == kBlack)
- fBlackNumber->SetValue((long)aNumber, TRUE);
- else if(aColor == kWhite)
- fWhiteNumber->SetValue((long)aNumber, TRUE);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TInfoView::SetPlayer(CellState aColor, Str255 aPlayerStr)
- {
- if(aColor == kBlack)
- fBlackText->SetText(aPlayerStr, FALSE);
- else if(aColor == kWhite)
- fWhiteText->SetText(aPlayerStr, FALSE);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TInfoView::ShowStatusMessage(Str255 & aMessage)
- {
- fStaticText->SetText(aMessage, TRUE);
- }
-
-
- // ============================== TStringView =================================
- #pragma segment AOpen
- pascal void TStringView::IRes(TDocument* itsDocument, TView* itsSuperView, TStream* itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- AddAdorner(gTaroApplication->GetTaroEraser(), kDrawView - 10, FALSE);
- fString = "";
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TStringView::Draw(const VRect& /*area*/)
- {
- Str255 aString = fString;
- Rect anQDExtent;
- Point aPoint;
- FontInfo aFontInfo;
-
- Focus();
- if(fDrawingEnvironment)
- ((TColorDrawingEnvironment *)fDrawingEnvironment)->Setup();
- GetQDExtent(anQDExtent);
- EraseRect(anQDExtent);
- short width = (anQDExtent.Size()).h;
- if(StringWidth(aString) > width)
- {
- OSErr anError = TruncString(width, aString, smTruncEnd);
- if((anError != smNotTruncated) && (anError != smTruncated) && (anError != smTruncErr))
- FailOSErr(anError);
- }
- GetFontInfo(aFontInfo);
- MoveTo(anQDExtent.left + (width - StringWidth(aString)) / 2, anQDExtent.top + aFontInfo.ascent);
- DrawString(aString);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TStringView::SetColor(CellState aColor)
- {
- fDrawingEnvironment = gTaroApplication->GetDrawingEnvironment(aColor);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TStringView::SetText(Str255 & aString, Boolean redraw)
- {
- fString = aString;
- if(redraw)
- {
- Rect aQDExtent;
-
- GetQDExtent(aQDExtent);
- Draw(aQDExtent);
- }
- }
-
- // ============================== TNumberStringView =================================
- #pragma segment ARes
- pascal void TNumberStringView::SetValue(long value, Boolean redraw)
- {
- Str255 aNumberString;
-
- NumToString(value, aNumberString);
- SetText(aNumberString, redraw);
- }
-
- // ============================== TVisibleCell =================================
- #pragma segment ADoCommand
- pascal void TVisibleCell::ChangeState(void)
- {
- inherited::ChangeState();
- (((TVisibleScene *)GetScene())->ReturnTaroGridView())->ForceRedrawCell(this);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleCell::PutPiece(void)
- {
- inherited::PutPiece();
- (((TVisibleScene *)GetScene())->ReturnTaroGridView())->SetEraseColor(this);
- }
-
-
- // ============================== TMousePlayer =================================
- #pragma segment AOpen
- pascal void TMousePlayer::IMousePlayer(TCoreDocument * aCoreDocument)
- {
- IPlayer(aCoreDocument);
- SetStatus(kReady);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TMousePlayer::MyTurn(void)
- {
- Str255 StatusMessage;
-
- GetIndString(StatusMessage, kStatusMessage, kMousePlayer);
- ((TVisibleDocument *)GetCoreDocument())->ShowStatusMessage(StatusMessage);
- inherited::MyTurn();
- if((((TVisibleDocument *)GetCoreDocument())->ReturnVisibleScene())->HasAvailableCell() == 0)
- {
- TMoveCommand * aMoveCommand = new TMoveCommand;
- FailNIL(aMoveCommand);
- aMoveCommand->IMoveCommand(this, NULL);
- gTaroApplication->PostCommand(aMoveCommand);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TMousePlayer::MouseMove(TRecordCell * aMouseMove)
- {
- TMoveCommand * aMoveCommand = new TMoveCommand;
- FailNIL(aMoveCommand);
- aMoveCommand->IMoveCommand(this, aMouseMove);
- gTaroApplication->PostCommand(aMoveCommand);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TMousePlayer::GetName(Str255 & aString)
- {
- GetIndString(aString, kPlayerString, kMousePlayer);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TMousePlayer::GameOver(GameResult aResult)
- {
- if(aResult == kWin)
- {
- Str255 GameOverMessage;
-
- GetIndString(GameOverMessage, kGameOverMessage, kMousePlayer);
- ((TVisibleDocument *)GetCoreDocument())->ShowStatusMessage(GameOverMessage);
- }
- }
-
-
- // ============================== TVisibleAEPlayer =================================
- #pragma segment AClose
- pascal void TVisibleAEPlayer::GameOver(GameResult aResult)
- {
- if(aResult == kWin)
- ShowPlayerMessage(kGameOverMessage);
- inherited::GameOver(aResult);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleAEPlayer::ShowPlayerMessage(short statusID)
- {
- Str255 GameOverMessage, PlayerName;
- Handle baseText = NewHandle(1);
- Handle substitutionText = NewHandle(1);
- Str15 KeyString;
- Str255 KeyStr255 = (char *)(**GetString(kSubstitutionKey));
-
- unsigned char length = KeyStr255.Length();
- if(length > 15)
- length = 15;
- strncpy((char *)&KeyString[1], (char *)KeyStr255, length);
- KeyString[0] = length;
-
- GetIndString(GameOverMessage, statusID, kRemoteAEPlayer);
- SetIText(baseText, GameOverMessage);
- GetName(PlayerName);
- SetIText(substitutionText, PlayerName);
- ReplaceText(baseText, substitutionText, KeyString);
- GetIText(baseText, GameOverMessage);
- DisposHandle(baseText);
- DisposHandle(substitutionText);
- ((TVisibleDocument *)GetCoreDocument())->ShowStatusMessage(GameOverMessage);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TVisibleAEPlayer::MyTurn(void)
- {
- if(!GetPermission())
- {
- ShowPlayerMessage(kStatusMessage);
- inherited::MyTurn();
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TVisibleAEPlayer::GetName(Str255 & aString)
- {
- ((TClientTarget *)ReturnTarget())->GetName(aString);
- }
-
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TVisibleAEPlayer::MyMove(TRecordCell * aMove)
- {
- gTaroApplication->PlaySound(kDive);
- inherited::MyMove(aMove);
- }
-
-
- // ============================== TServerAEPlayer =================================
- #pragma segment AOpen
- pascal void TServerAEPlayer::IServerAEPlayer(TCoreDocument * aCoreDocument, CellState aColor)
- {
- SetCoreDocument(aCoreDocument);
- SetMyColor(aColor);
- SetStatus(kReady);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TServerAEPlayer::Free(void)
- {
- ReturnTarget()->Free();
- inherited::Free();
- }
-
-
- // ============================== TClientAEPlayer =================================
- #pragma segment AOpen
- pascal void TClientAEPlayer::IClientAEPlayer(TCoreDocument * aCoreDocument,
- CellState aColor, TClientTarget * aClientTarget)
- {
- aClientTarget->SendBeginTransaction((long)this);
- IAppleEventPlayer(aCoreDocument, aColor);
- SetTarget(aClientTarget);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TClientAEPlayer::TargetReply(unsigned long aTargetTransactionID)
- {
- SetTargetTransactionID(aTargetTransactionID);
- if(aTargetTransactionID != 0)
- {
- char HCellSize, VCellSize;
- ((TClientTarget *)ReturnTarget())->AddUser(this);
-
- GetCoreDocument()->GetCellSize(HCellSize, VCellSize);
- ((TClientTarget *)ReturnTarget())->SendNewElement(HCellSize, VCellSize, GetMyColor(), this, aTargetTransactionID);
- }
- else
- SetStatus(kFailed);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TClientAEPlayer::SetTargetTableSpecifier(AEDesc & aTargetSpec)
- {
- if(aTargetSpec.descriptorType != typeNull)
- {
- inherited::SetTargetTableSpecifier(aTargetSpec);
- SetStatus(kReady);
- }
- else
- SetStatus(kFailed);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TClientAEPlayer::TargetDied(void)
- {
- ((TVisibleDocument *)GetCoreDocument())->GameClose();
- }
-
-
- // ============================== TClientTarget =================================
- #pragma segment AOpen
- pascal void TClientTarget::IClientTarget(void)
- {
- TList * aList = NewList();
- FailNIL(aList);
- fUserList = aList;
- fUserList->SetEltType("TClientAEPlayer");
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TClientTarget::Remove(void)
- {
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TClientTarget::Free(void)
- {
- fUserList->DeleteAll();
- fUserList->Free();
- inherited::Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TClientTarget::AddUser(TClientAEPlayer * theClient)
- {
- fUserList->InsertLast(theClient);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TClientTarget::SendNewElement(char HCellSize, char VCellSize, CellState aColor,
- TVisibleAEPlayer * theClient, unsigned long aTransactionID)
- {
- TAppleEvent * theAppleEvent;
- DescType ElementType = cTable;
- AEDesc dNull;
- AERecord ElementList;
- short hSize = HCellSize;
- short vSize = VCellSize;
- long color = aColor;
-
- theAppleEvent = CreateAppleEvent(kAECoreSuite, kAENewElement,
- kNewElementReturnID, aTransactionID);
- theAppleEvent->WriteParameterPtr(keyAEObjectClass, typeType,
- (Ptr)&ElementType, sizeof(ElementType));
- FailOSErr(AECreateDesc(typeNull, NULL, 0, dNull));
- theAppleEvent->WriteParameter(keyAEInsertHere, dNull);
- FailOSErr(AECreateList(NULL, 0, TRUE, ElementList));
- FailOSErr(AEPutKeyPtr(ElementList, keyTaroColumnNumber, typeShortInteger, (Ptr)&hSize, sizeof(hSize)));
- FailOSErr(AEPutKeyPtr(ElementList, keyTaroRowNumber, typeShortInteger, (Ptr)&vSize, sizeof(vSize)));
- FailOSErr(AEPutKeyPtr(ElementList, keyTaroColor, typeEnumerated, (Ptr)&color, sizeof(color)));
- StringHandle UserName = GetString(-16096);
- if(UserName == NULL)
- FailNILResource((Handle)(UserName = GetString(-16413)));
- LockHandleHigh((Handle)UserName);
- FailOSErr(AEPutKeyPtr(ElementList, keyTaroUserName, typeChar, (char *)(**UserName), (**UserName).Length()));
- HUnlock((Handle)UserName);
-
- AEDesc tableSpec;
- (theClient->GetCoreDocument())->CreateTableSpecifier(tableSpec);
- FailOSErr(AEPutKeyDesc(ElementList, keyTaroTableSpecifier, tableSpec));
- theAppleEvent->WriteParameter(keyAEData, ElementList);
- theAppleEvent->SetSendingMode(kAEQueueReply + kAECanInteract + kAECanSwitchLayer);
- theAppleEvent->Send();
- theAppleEvent->Free();
- FailOSErr(AEDisposeDesc(dNull));
- FailOSErr(AEDisposeDesc(tableSpec));
- FailOSErr(AEDisposeDesc(ElementList));
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TClientTarget::SendBeginTransaction(long & aTransactionID)
- {
- TAppleEvent * theAppleEvent;
-
- theAppleEvent = CreateAppleEvent(kAECoreSuite, kAEBeginTransaction,
- kBeginTransactionReturnID, aTransactionID);
- theAppleEvent->SetSendingMode(kAEQueueReply);
- theAppleEvent->Send();
- theAppleEvent->Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TClientTarget::SendEndTransaction(GameResult aResult, unsigned long theServer, TPlayer * theClient)
- {
- inherited::SendEndTransaction(aResult, theServer, theClient);
- fUserList->Delete(theClient);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TClientTarget::GetName(Str255 &/*aString*/)
- {
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TClientTarget::SendQuitApplication(void)
- {
- TAppleEvent * theAppleEvent;
-
- theAppleEvent = CreateAppleEvent(kCoreEventClass, kAEQuitApplication,
- kAutoGenerateReturnID, kAnyTransactionID);
- theAppleEvent->SetSendingMode(kAENoReply);
- theAppleEvent->Send();
- theAppleEvent->Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal short TClientTarget::GetUserCount(void)
- {
- return (short)fUserList->GetSize();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TClientTarget::TellUsersThatProcessDied(void)
- {
- CObjectIterator iter(fUserList);
-
- for (TClientAEPlayer * user = (TClientAEPlayer *)iter.FirstObject(); iter.More(); user = (TClientAEPlayer *)iter.NextObject())
- user->TargetDied();
- }
-
-
- // ============================== TPPCTarget =================================
- #pragma segment AOpen
- pascal void TPPCTarget::IPPCTarget(TargetIDHdl aTargetID)
- {
- fTargetID = aTargetID;
- HLock((Handle)fTargetID);
- CreateDesc(typeTargetID, (Ptr)(*fTargetID), sizeof(**fTargetID));
- HUnlock((Handle)fTargetID);
- IClientTarget();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPPCTarget::GetName(Str255 & aString)
- {
- Str32 targetName;
- HLock((Handle)fTargetID);
- switch((*fTargetID)->location.locationKindSelector)
- {
- default:
- case ppcNoLocation:
- targetName = (*fTargetID)->name.name;
- break;
- case ppcNBPLocation:
- targetName = (*fTargetID)->location.u.nbpEntity.objStr;
- break;
- case ppcNBPTypeLocation:
- targetName = (*fTargetID)->location.u.nbpType;
- break;
- }
- HUnlock((Handle)fTargetID);
- memcpy((void *)&aString, (void *)&targetName, targetName.Length() + 1);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TPPCTarget::Remove(void)
- {
- RmveResource((Handle)fTargetID);
- FailResError();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPPCTarget::Free(void)
- {
- DisposHandle((Handle)fTargetID);
- inherited::Free();
- }
-
- // ============================== TPSNTarget =================================
- #pragma segment AOpen
- pascal void TPSNTarget::IPSNTarget(AliasHandle aFile)
- {
- fFile = aFile;
- fProcess.highLongOfPSN = 0;
- fProcess.lowLongOfPSN = 0;
- CreateDesc(typeNull, NULL, (Size)0);
- IClientTarget();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal Boolean TPSNTarget::TestProcess(void)
- {
- if((fProcess.highLongOfPSN == 0) && (fProcess.lowLongOfPSN == 0))
- return FALSE;
- else
- return TRUE;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TPSNTarget::LaunchProcess(void)
- {
- if(!TestProcess())
- {
- LaunchParamBlockRec MyLPBRec;
- FSSpec TargetFSSpec;
-
- MyLPBRec.launchBlockID = extendedBlock;
- MyLPBRec.launchEPBLength = extendedBlockLen;
- MyLPBRec.launchControlFlags = launchContinue + launchNoFileFlags + launchDontSwitch;
- MyLPBRec.launchAppParameters = NULL;
- GetFSSpec(TargetFSSpec);
- MyLPBRec.launchAppSpec = &TargetFSSpec;
- FailOSErr(LaunchApplication(MyLPBRec));
- CreateDesc(typeProcessSerialNumber, (Ptr)&MyLPBRec.launchProcessSN, sizeof(MyLPBRec.launchProcessSN));
- fProcess = MyLPBRec.launchProcessSN;
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPSNTarget::GetFSSpec(FSSpec & aFile)
- {
- Boolean wasChanged;
-
- FailOSErr(ResolveAlias(NULL, fFile, aFile, wasChanged));
- if(wasChanged)
- {
- ChangedResource((Handle)fFile);
- FailResError();
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPSNTarget::SendBeginTransaction(long & aTransactionID)
- {
- LaunchProcess();
- inherited::SendBeginTransaction(aTransactionID);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AClose
- pascal void TPSNTarget::SendEndTransaction(GameResult aResult, unsigned long theServer, TPlayer * theClient)
- {
- if(TestProcess())
- inherited::SendEndTransaction(aResult, theServer, theClient);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPSNTarget::GetName(Str255 & aString)
- {
- FSSpec aFile;
-
- GetFSSpec(aFile);
- aString = aFile.name;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TPSNTarget::Remove(void)
- {
- RmveResource((Handle)fFile);
- FailResError();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPSNTarget::Free(void)
- {
- if(TestProcess())
- SendQuitApplication();
- DisposHandle((Handle)fFile);
- inherited::Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TPSNTarget::CompareProcess(ProcessSerialNumber & theProcess)
- {
- Boolean Result;
-
- Lock(TRUE);
- OSErr Error = SameProcess(theProcess, fProcess, Result);
- Lock(FALSE);
- FailOSErr(Error);
- if(Result)
- {
- fProcess.highLongOfPSN = 0;
- fProcess.lowLongOfPSN = 0;
- TellUsersThatProcessDied();
- };
- }
-
-
- // ============================== TColorDrawingEnvironment =================================
- #pragma segment AOpen
- pascal void TColorDrawingEnvironment::Initialize(void)
- {
- inherited::Initialize();
- fColorTableHandle = NULL;
- for(DrawPart aPart = kForeground; aPart < kDrawPartEnd; aPart++)
- fPixPatTable[aPart] = NULL;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TColorDrawingEnvironment::Free(void)
- {
- DisposHandle((Handle)fColorTableHandle);
- for(DrawPart aPart = kForeground; aPart < kDrawPartEnd; aPart++)
- DisposPixPat(fPixPatTable[aPart]);
- inherited::Free();
- }
-
- // ------------------------------------------------------------------------
- #pragma segment AOpen
- pascal void TColorDrawingEnvironment::IColorDrawingEnvironment(short aColorTableID)
- {
- IDrawingEnvironment();
- fID = aColorTableID;
-
- if(gConfiguration.hasColorQD)
- {
- FailNILResource((Handle)(fColorTableHandle = GetCTable(aColorTableID)));
- fBackgroundColor = ((*fColorTableHandle)->ctTable[1]).rgb;
- for(DrawPart aPart = kForeground; aPart < kDrawPartEnd; aPart++)
- fPixPatTable[aPart] = NewPixPat();
- MakePixPatTable();
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TColorDrawingEnvironment::SetupAdornerColor(DrawPart aPart)
- {
- Setup();
- if(gColorAvailable)
- PenPixPat(fPixPatTable[aPart]);
- else
- {
- Pattern fore;
- GetIndPattern(fore, fID, aPart + 1);
- PenPat(fore);
- }
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TColorDrawingEnvironment::Setup(void)
- {
- if(!gColorAvailable)
- {
- Pattern fore, back;
- fForegroundColor = gRGBBlack;
- fBackgroundColor = gRGBWhite;
- GetIndPattern(fore, fID, kForeground + 1);
- memcpy(fPenPattern, fore, 8);
- inherited::Setup();
- GetIndPattern(back, fID, kBackground + 1);
- BackPat(back);
- }
- else
- {
- inherited::Setup();
- PenPixPat(fPixPatTable[kForeground]);
- BackPixPat(fPixPatTable[kBackground]);
- }
- if(fID == kBlackCTable)
- TextMode(srcBic);
- else
- TextMode(srcOr);
- TextFont(0);
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ARes
- pascal void TColorDrawingEnvironment::MakePixPatTable(void)
- {
- for(DrawPart aPart = kForeground; aPart < kDrawPartEnd; aPart++)
- MakeRGBPat(fPixPatTable[aPart], ((*fColorTableHandle)->ctTable[aPart]).rgb);
- }
-
- // ============================== TTaroEraser =================================
- #pragma segment ARes
- pascal void TTaroEraser::Draw(TView * itsView, const VRect& area)
- {
- TDrawingEnvironment * aDrawingEnvironment = itsView->GetDrawingEnvironment();
- if(aDrawingEnvironment)
- aDrawingEnvironment->Setup();
- inherited::Draw(itsView, area);
- }
-
- // ============================== TSoundCommand =================================
- #pragma segment AOpen
- pascal void TSoundCommand::ISoundCommand(SoundEffect aSound)
- {
- inherited::ICommand(0, NULL, FALSE, FALSE, NULL);
- fSound = aSound;
- }
-
- // ------------------------------------------------------------------------
- #pragma segment ADoCommand
- pascal void TSoundCommand::DoIt(void)
- {
- gTaroApplication->PlaySound(fSound);
- fCommandDone = TRUE;
- }
-
-